package com.yonyou.pmclouds.plan.mapper;

import com.yonyou.pmclouds.basecom.dao.BaseMapper;
import com.yonyou.pmclouds.plan.entity.ProjectPlanVO;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

public interface ProjectPlanMapper extends BaseMapper<ProjectPlanVO> {
    int countRootPlanOfProject(String projectId);

    String[] getChildrenPks(String planId);

    int deceaseChildCount(@Param("planId") String planId, @Param("descNum") int descNum);

    int deceaseChildSeqAfterNo(@Param("parent") String parent, @Param("projectId") String projectId, @Param("no") int no);

    /**
     * 批量是删除计划，需要控制输入的pk数量，避免sql过长
     */
    int deletePlanBatch(String[] pks);

    Date earliestDateOfParentExpectSpecialChild(@Param("parent") String parent, @Param("child") String child);

    Date latestDateOfParentExpectSpecialChild(@Param("parent") String parent, @Param("child") String child);

    ProjectPlanVO[] queryProjectPlan(String projectId);

    ProjectPlanVO[] queryPlanByRoot(String rootId);

    ProjectPlanVO[] queryLeafByRoot(String rootId);

    ProjectPlanVO[] queryPlanByTenantId(@Param("tenantId") String tenantId);

    ProjectPlanVO[] queryLastPlanByProject(String projectId);

    ProjectPlanVO[] queryLastPlanByProjects(@Param("projectIds") String projectIds);

    ProjectPlanVO[] queryhistoryPlan(String planId);

    ProjectPlanVO[] queryPlanBySrcAndVersion(@Param("srcId") String srcId, @Param("version") int version);


    //根据pkPlan查询ProjectPlan对象
    ProjectPlanVO queryByPkPlan(@Param("pkPlan")String pkPlan);

    /**
     * 校验里程碑是否被计划引用
     *
     * @param pkMilestone
     * @return
     */
    int countMilestoneRelatedPlan(@Param("pkMilestone") String pkMilestone);

    ProjectPlanVO[] queryByProjectAndRelatedBillType(@Param("pkProject") String pkProject, @Param("billTypes") List<String> billTypes);

    ProjectPlanVO[] queryChildPlanByParents(@Param("pkParents") String[] pkParents);

    List<ProjectPlanVO> queryByPkPlans(@Param("pkPlans") String[] pkPlans);

    List<ProjectPlanVO> queryByProjectAndDependPlan(@Param("pkProject") String pkProject, @Param("dependPlans") String[] dependPlans);

    ProjectPlanVO[] queryDefaultProjectPlan(@Param("pkProject") String pkProject,@Param("sname") String sname,@Param("scode") String scode);

    ProjectPlanVO[] queryMillStonePlanById(@Param("pkProject") String pkProject, @Param("pkPlan") String pkPlan);

    /**
     *
     * @param pkProject
     * @return 根据项目id 查询所有根计划
     */
    ProjectPlanVO[] queryRootPlanByProjectId(@Param("pkProject") String pkProject);

}
